#ifndef __GENERATOR_H__
#define __GENERATOR_H__

#include "common.h"

//#define EDITOR_MODE

enum {
	TSHIFT=9,
	TSIZE=(1<<TSHIFT),
	TMASK=(1<<TSHIFT)-1,
	TEXSIZE=TSIZE*TSIZE
};

struct Action {
  char8 type;
  char8 mask;
  char8 op;
  char8 layer,data1,data2;
  char8 param1,param2,param3,param4;
  int32 nameparam;
};

class Generator {
  Action actions[256]; //256 should be enough :)
  int numactions;
#ifdef EDITOR_MODE
  int totalactions;
#endif
  int32 *layers[4];
  int32 masks[16];
public:
  Generator();
  void reset();
  void execute_all();
  void execute(Action &action);
  void startover() {
    numactions=0;
#ifdef EDITOR_MODE  
    totalactions=0;
#endif
    reset();
  }
  void readfrommem(char8 *mem);
  int32 *getlayer(int i) {if (i>=0 && i<=3) return layers[i]; else return 0;}
#ifdef EDITOR_MODE  
  ~Generator();
  void writetomem(char8 *mem);
  int sizeoftex();
  void add(Action &action);
  void add_and_execute(Action &action);
  void del(int i);
  void up(int i);
  void down(int i);
  void undo();
  void redo();
  void tolist(CListBox &list);
  void load(const char *filename, int32 &ID);
  void save(const char *filename, int32 ID);
  int count() {return numactions;}
#endif
};

#ifdef EDITOR_MODE

struct ActionInfo {
  char *name;
  bool usedata1;
  bool usedata2;
  int numparams;
  char *param1name,
       *param2name,
       *param3name,
       *param4name;
  char *nameparamname;
};

extern ActionInfo actioninfo[32];

#endif

#endif //__GENERATOR_H__